package org.example.struct.array;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author liyishan
 * @date 2024/7/29 10:52
 * @apiNote
 */

public class Test01029TwoCitySchedCost {

    public int twoCitySchedCost(int[][] costs) {
        Arrays.sort(costs , Comparator.comparingInt(a -> (a[0] - a[1])));
        int total = 0;
        int n = costs.length / 2;
        for(int i =0;i<n;i++){
            total += costs[i][0] + costs[i + n][1];
        }
        return total;
    }
}
